package _bye_util;

import java.util.SortedSet;
import java.util.TreeSet;

/**
 * 
 * @author kagioglu
 */
public class LogLeakyIntRecycler implements IntRecycler
{
    private int nextInt;
    private SortedSet< Integer > trash;
    
    public LogLeakyIntRecycler() {
        this.nextInt = 0;
        this.trash = new TreeSet< Integer >();
    }
    
    public int newInt()
    {
        int temp;
        if ( this.trash.isEmpty() )
        {
            return this.nextInt++;
        }
        else
        {
            temp = this.trash.first();
            this.trash.remove( temp );
            return temp;
        }
    }
    
    public void recycleInt( int garbage )
    {
        this.trash.add( garbage );
    }
}
